{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "59ab02d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "5a889ac8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url (目标餐厅)\n",
    "face_detect_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "# 2. 准备API_key\n",
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'image_url':'https://tse1-mm.cn.bing.net/th/id/OIP-C.HPWFQ7UDQh93EKcDmiUQ_wHaIR?w=176&h=197&c=7&r=0&o=5&dpr=2&pid=1.7'\n",
    "}\n",
    "r = requests.post(face_detect_url,params = payload)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "1f5b8632",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "7c5126c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647678496,68cb09f2-91b9-4fe5-a9a6-04047cdbfea8',\n",
       " 'time_used': 620,\n",
       " 'faces': [{'face_token': '76b47a75a959195ad9a089bdb73a0a81',\n",
       "   'face_rectangle': {'top': 262, 'left': 299, 'width': 338, 'height': 338}}],\n",
       " 'image_id': 'IzlLTp6TGVpTdTq0pBGBiw==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "a33a59b6",
   "metadata": {},
   "source": [
    "1647344149,1d6f5db9-5613-4849-8423-12ea9a26699d\n",
    "3c4e5f167a4ff02f33a057fbbb052cd8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c8e50425",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2. 人脸分析 （尝试调用analyze接口）\n",
    "\n",
    "# 1. url (目标餐厅)\n",
    "face_detect_url = \"https://api-cn.faceplusplus.com/facepp/v3/face/analyze\"\n",
    "\n",
    "# 2. 准备API_key\n",
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'face_tokens':'b4af9445c9e3b18e7417561ce889f3d3',\n",
    "    'return_attributes':'gender,age,smiling,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus'\n",
    "}\n",
    "r = requests.post(face_detect_url,params = payload)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ff5d440e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 137,\n",
       " 'request_id': '1647678248,a5b01e74-1612-4671-96e3-91c6462174c3',\n",
       " 'faces': [{'attributes': {'emotion': {'sadness': 0.681,\n",
       "     'neutral': 0.007,\n",
       "     'disgust': 1.213,\n",
       "     'anger': 0.007,\n",
       "     'surprise': 0.009,\n",
       "     'fear': 0.112,\n",
       "     'happiness': 97.97},\n",
       "    'beauty': {'female_score': 56.631, 'male_score': 56.694},\n",
       "    'gender': {'value': 'Male'},\n",
       "    'age': {'value': 53},\n",
       "    'mouthstatus': {'close': 0.0,\n",
       "     'surgical_mask_or_respirator': 0.0,\n",
       "     'open': 100.0,\n",
       "     'other_occlusion': 0.0},\n",
       "    'glass': {'value': 'None'},\n",
       "    'skinstatus': {'dark_circle': 1.982,\n",
       "     'stain': 12.624,\n",
       "     'acne': 0.634,\n",
       "     'health': 9.525},\n",
       "    'blur': {'blurness': {'threshold': 50.0, 'value': 0.364},\n",
       "     'motionblur': {'threshold': 50.0, 'value': 0.364},\n",
       "     'gaussianblur': {'threshold': 50.0, 'value': 0.364}},\n",
       "    'smile': {'threshold': 50.0, 'value': 100.0},\n",
       "    'eyestatus': {'left_eye_status': {'normal_glass_eye_open': 0.002,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 99.998,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0},\n",
       "     'right_eye_status': {'normal_glass_eye_open': 0.031,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.008,\n",
       "      'no_glass_eye_open': 99.961,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0}},\n",
       "    'facequality': {'threshold': 70.1, 'value': 85.658},\n",
       "    'eyegaze': {'right_eye_gaze': {'position_x_coordinate': 0.468,\n",
       "      'vector_z_component': 0.944,\n",
       "      'vector_x_component': -0.054,\n",
       "      'vector_y_component': 0.325,\n",
       "      'position_y_coordinate': 0.443},\n",
       "     'left_eye_gaze': {'position_x_coordinate': 0.506,\n",
       "      'vector_z_component': 0.948,\n",
       "      'vector_x_component': 0.168,\n",
       "      'vector_y_component': 0.269,\n",
       "      'position_y_coordinate': 0.436}}},\n",
       "   'face_rectangle': {'width': 107, 'top': 108, 'left': 141, 'height': 107},\n",
       "   'face_token': 'b4af9445c9e3b18e7417561ce889f3d3'}]}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "525d8236",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "98edca31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>face_token</th>\n",
       "      <td>b4af9445c9e3b18e7417561ce889f3d3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.sadness</th>\n",
       "      <td>0.681</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.neutral</th>\n",
       "      <td>0.007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.disgust</th>\n",
       "      <td>1.213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.anger</th>\n",
       "      <td>0.007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.surprise</th>\n",
       "      <td>0.009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.fear</th>\n",
       "      <td>0.112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.happiness</th>\n",
       "      <td>97.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.beauty.female_score</th>\n",
       "      <td>56.631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.beauty.male_score</th>\n",
       "      <td>56.694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.gender.value</th>\n",
       "      <td>Male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.age.value</th>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.surgical_mask_or_respirator</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.open</th>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.other_occlusion</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.glass.value</th>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.dark_circle</th>\n",
       "      <td>1.982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.stain</th>\n",
       "      <td>12.624</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.acne</th>\n",
       "      <td>0.634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.health</th>\n",
       "      <td>9.525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.blurness.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.blurness.value</th>\n",
       "      <td>0.364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.motionblur.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.motionblur.value</th>\n",
       "      <td>0.364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.gaussianblur.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.gaussianblur.value</th>\n",
       "      <td>0.364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.smile.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.smile.value</th>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.normal_glass_eye_open</th>\n",
       "      <td>0.002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.no_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.occlusion</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.no_glass_eye_open</th>\n",
       "      <td>99.998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.normal_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.dark_glasses</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.normal_glass_eye_open</th>\n",
       "      <td>0.031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.no_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.occlusion</th>\n",
       "      <td>0.008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.no_glass_eye_open</th>\n",
       "      <td>99.961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.normal_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.dark_glasses</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.facequality.threshold</th>\n",
       "      <td>70.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.facequality.value</th>\n",
       "      <td>85.658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.position_x_coordinate</th>\n",
       "      <td>0.468</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_z_component</th>\n",
       "      <td>0.944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_x_component</th>\n",
       "      <td>-0.054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_y_component</th>\n",
       "      <td>0.325</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.position_y_coordinate</th>\n",
       "      <td>0.443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.position_x_coordinate</th>\n",
       "      <td>0.506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.vector_z_component</th>\n",
       "      <td>0.948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.vector_x_component</th>\n",
       "      <td>0.168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.vector_y_component</th>\n",
       "      <td>0.269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.position_y_coordinate</th>\n",
       "      <td>0.436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <td>108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.height</th>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                                   0\n",
       "face_token                                          b4af9445c9e3b18e7417561ce889f3d3\n",
       "attributes.emotion.sadness                                                     0.681\n",
       "attributes.emotion.neutral                                                     0.007\n",
       "attributes.emotion.disgust                                                     1.213\n",
       "attributes.emotion.anger                                                       0.007\n",
       "attributes.emotion.surprise                                                    0.009\n",
       "attributes.emotion.fear                                                        0.112\n",
       "attributes.emotion.happiness                                                   97.97\n",
       "attributes.beauty.female_score                                                56.631\n",
       "attributes.beauty.male_score                                                  56.694\n",
       "attributes.gender.value                                                         Male\n",
       "attributes.age.value                                                              53\n",
       "attributes.mouthstatus.close                                                     0.0\n",
       "attributes.mouthstatus.surgical_mask_or_respirator                               0.0\n",
       "attributes.mouthstatus.open                                                    100.0\n",
       "attributes.mouthstatus.other_occlusion                                           0.0\n",
       "attributes.glass.value                                                          None\n",
       "attributes.skinstatus.dark_circle                                              1.982\n",
       "attributes.skinstatus.stain                                                   12.624\n",
       "attributes.skinstatus.acne                                                     0.634\n",
       "attributes.skinstatus.health                                                   9.525\n",
       "attributes.blur.blurness.threshold                                              50.0\n",
       "attributes.blur.blurness.value                                                 0.364\n",
       "attributes.blur.motionblur.threshold                                            50.0\n",
       "attributes.blur.motionblur.value                                               0.364\n",
       "attributes.blur.gaussianblur.threshold                                          50.0\n",
       "attributes.blur.gaussianblur.value                                             0.364\n",
       "attributes.smile.threshold                                                      50.0\n",
       "attributes.smile.value                                                         100.0\n",
       "attributes.eyestatus.left_eye_status.normal_gla...                             0.002\n",
       "attributes.eyestatus.left_eye_status.no_glass_e...                               0.0\n",
       "attributes.eyestatus.left_eye_status.occlusion                                   0.0\n",
       "attributes.eyestatus.left_eye_status.no_glass_e...                            99.998\n",
       "attributes.eyestatus.left_eye_status.normal_gla...                               0.0\n",
       "attributes.eyestatus.left_eye_status.dark_glasses                                0.0\n",
       "attributes.eyestatus.right_eye_status.normal_gl...                             0.031\n",
       "attributes.eyestatus.right_eye_status.no_glass_...                               0.0\n",
       "attributes.eyestatus.right_eye_status.occlusion                                0.008\n",
       "attributes.eyestatus.right_eye_status.no_glass_...                            99.961\n",
       "attributes.eyestatus.right_eye_status.normal_gl...                               0.0\n",
       "attributes.eyestatus.right_eye_status.dark_glasses                               0.0\n",
       "attributes.facequality.threshold                                                70.1\n",
       "attributes.facequality.value                                                  85.658\n",
       "attributes.eyegaze.right_eye_gaze.position_x_co...                             0.468\n",
       "attributes.eyegaze.right_eye_gaze.vector_z_comp...                             0.944\n",
       "attributes.eyegaze.right_eye_gaze.vector_x_comp...                            -0.054\n",
       "attributes.eyegaze.right_eye_gaze.vector_y_comp...                             0.325\n",
       "attributes.eyegaze.right_eye_gaze.position_y_co...                             0.443\n",
       "attributes.eyegaze.left_eye_gaze.position_x_coo...                             0.506\n",
       "attributes.eyegaze.left_eye_gaze.vector_z_compo...                             0.948\n",
       "attributes.eyegaze.left_eye_gaze.vector_x_compo...                             0.168\n",
       "attributes.eyegaze.left_eye_gaze.vector_y_compo...                             0.269\n",
       "attributes.eyegaze.left_eye_gaze.position_y_coo...                             0.436\n",
       "face_rectangle.width                                                             107\n",
       "face_rectangle.top                                                               108\n",
       "face_rectangle.left                                                              141\n",
       "face_rectangle.height                                                            107"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(r.json()['faces'][0]).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "e3395079",
   "metadata": {},
   "outputs": [],
   "source": [
    "liu_face01 = '76b47a75a959195ad9a089bdb73a0a81'\n",
    "liu_face02 = 'b4af9445c9e3b18e7417561ce889f3d3'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "7c89e051",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3. 人脸对比 \n",
    "\n",
    "# 1. url (目标餐厅)\n",
    "face_analyze_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "\n",
    "# 2. 准备API_key\n",
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'face_token1':liu_face01,\n",
    "    'face_token2':liu_face02\n",
    "}\n",
    "r = requests.post(face_analyze_url,params = payload)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "94f7ecb6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "27a96dac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647678575,12f32315-6ca6-477a-99e6-9384085a9747',\n",
       " 'time_used': 302,\n",
       " 'confidence': 85.244,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}}"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1511629d",
   "metadata": {},
   "source": [
    " 4.人脸检测函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "d301bc31",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "e7d00c06",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "image_url = 'https://img.kuyv.cn/202011/07/165359721.jpg'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "cfb95a74",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：能否将一些功能做函数的封装，实现更加便捷的API调用\n",
    "def face_detect(API_key,API_secret,image_url,landmark=None,attributes=None,face_rectangle=None,beauty_score_min=0,beauty_score_max=100):\n",
    "    \"\"\"face++ 人脸检测接口函数(图片链接)\"\"\"\n",
    "    url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "    payload={\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'image_url':image_url,\n",
    "        'return_landmark':landmark,\n",
    "        'return_attributes':attributes,\n",
    "        'face_rectangle':face_rectangle,\n",
    "        'beauty_score_min':beauty_score_min,\n",
    "        'beauty_score_max':beauty_score_max   \n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "90ffe9cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647678592,543df817-c8c5-47c9-82d9-07aacc2ad9e0',\n",
       " 'time_used': 526,\n",
       " 'faces': [{'face_token': 'd488b20287a4a2d952e0731ff68fbb4e',\n",
       "   'face_rectangle': {'top': 231, 'left': 323, 'width': 313, 'height': 313}}],\n",
       " 'image_id': 'aBgODNUGne9Or5b4Mv9ZIg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 调用函数\n",
    "face_detect(API_key,API_secret,image_url)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7be2f39",
   "metadata": {},
   "source": [
    "作业1："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "c41988d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2. 人脸分析 （尝试调用analyze接口）\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "de263083",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "face_tokens = 'd488b20287a4a2d952e0731ff68fbb4e'\n",
    "return_landmark = 1\n",
    "return_attributes = 'gender,age,smiling,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "4ce40713",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_analyze(API_key,API_secret,face_tokens,return_landmark,return_attributes,beauty_score_min=0,beauty_score_max=100):\n",
    "    url = \"https://api-cn.faceplusplus.com/facepp/v3/face/analyze\"\n",
    "    payload = {\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'face_tokens':face_tokens,\n",
    "        'return_landmark':return_landmark,\n",
    "        'return_attributes':return_attributes,\n",
    "        'beauty_score_min':beauty_score_min,\n",
    "        'beauty_score_max':beauty_score_max   \n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "d7f43fd3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "cab04098",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 192,\n",
       " 'request_id': '1647678864,5b4df99c-ae74-4e3e-9266-9bcade7cf490',\n",
       " 'faces': [{'landmark': {'mouth_upper_lip_left_contour2': {'y': 441, 'x': 489},\n",
       "    'mouth_upper_lip_top': {'y': 444, 'x': 530},\n",
       "    'mouth_upper_lip_left_contour1': {'y': 438, 'x': 517},\n",
       "    'left_eye_upper_left_quarter': {'y': 273, 'x': 465},\n",
       "    'left_eyebrow_lower_middle': {'y': 254, 'x': 482},\n",
       "    'mouth_upper_lip_left_contour3': {'y': 451, 'x': 496},\n",
       "    'right_eye_top': {'y': 306, 'x': 614},\n",
       "    'left_eye_bottom': {'y': 295, 'x': 475},\n",
       "    'right_eyebrow_lower_left_quarter': {'y': 288, 'x': 615},\n",
       "    'right_eye_pupil': {'y': 315, 'x': 613},\n",
       "    'mouth_lower_lip_right_contour1': {'y': 463, 'x': 548},\n",
       "    'mouth_lower_lip_right_contour3': {'y': 482, 'x': 542},\n",
       "    'mouth_lower_lip_right_contour2': {'y': 474, 'x': 556},\n",
       "    'contour_chin': {'y': 548, 'x': 501},\n",
       "    'contour_left9': {'y': 536, 'x': 458},\n",
       "    'left_eye_lower_right_quarter': {'y': 297, 'x': 492},\n",
       "    'mouth_lower_lip_top': {'y': 461, 'x': 526},\n",
       "    'right_eyebrow_upper_middle': {'y': 271, 'x': 633},\n",
       "    'left_eyebrow_left_corner': {'y': 245, 'x': 432},\n",
       "    'right_eye_bottom': {'y': 326, 'x': 612},\n",
       "    'contour_left7': {'y': 480, 'x': 389},\n",
       "    'contour_left6': {'y': 447, 'x': 362},\n",
       "    'contour_left5': {'y': 410, 'x': 343},\n",
       "    'contour_left4': {'y': 371, 'x': 334},\n",
       "    'contour_left3': {'y': 330, 'x': 335},\n",
       "    'contour_left2': {'y': 290, 'x': 342},\n",
       "    'contour_left1': {'y': 252, 'x': 354},\n",
       "    'left_eye_lower_left_quarter': {'y': 288, 'x': 460},\n",
       "    'contour_right1': {'y': 330, 'x': 648},\n",
       "    'contour_right3': {'y': 389, 'x': 641},\n",
       "    'contour_right2': {'y': 359, 'x': 645},\n",
       "    'mouth_left_corner': {'y': 445, 'x': 461},\n",
       "    'contour_right4': {'y': 419, 'x': 630},\n",
       "    'contour_right7': {'y': 495, 'x': 576},\n",
       "    'right_eyebrow_left_corner': {'y': 286, 'x': 597},\n",
       "    'nose_right': {'y': 398, 'x': 581},\n",
       "    'nose_tip': {'y': 388, 'x': 551},\n",
       "    'contour_right5': {'y': 446, 'x': 614},\n",
       "    'nose_contour_lower_middle': {'y': 413, 'x': 540},\n",
       "    'left_eyebrow_lower_left_quarter': {'y': 250, 'x': 457},\n",
       "    'mouth_lower_lip_left_contour3': {'y': 474, 'x': 497},\n",
       "    'right_eye_right_corner': {'y': 319, 'x': 634},\n",
       "    'right_eye_lower_right_quarter': {'y': 325, 'x': 625},\n",
       "    'mouth_upper_lip_right_contour2': {'y': 453, 'x': 559},\n",
       "    'right_eyebrow_lower_right_quarter': {'y': 289, 'x': 647},\n",
       "    'left_eye_left_corner': {'y': 278, 'x': 449},\n",
       "    'mouth_right_corner': {'y': 464, 'x': 569},\n",
       "    'mouth_upper_lip_right_contour3': {'y': 460, 'x': 549},\n",
       "    'right_eye_lower_left_quarter': {'y': 322, 'x': 597},\n",
       "    'left_eyebrow_right_corner': {'y': 268, 'x': 534},\n",
       "    'left_eyebrow_lower_right_quarter': {'y': 262, 'x': 508},\n",
       "    'right_eye_center': {'y': 317, 'x': 611},\n",
       "    'nose_left': {'y': 382, 'x': 493},\n",
       "    'mouth_lower_lip_left_contour1': {'y': 454, 'x': 495},\n",
       "    'left_eye_upper_right_quarter': {'y': 283, 'x': 498},\n",
       "    'right_eyebrow_lower_middle': {'y': 288, 'x': 632},\n",
       "    'left_eye_top': {'y': 274, 'x': 483},\n",
       "    'left_eye_center': {'y': 286, 'x': 479},\n",
       "    'contour_left8': {'y': 510, 'x': 421},\n",
       "    'contour_right9': {'y': 540, 'x': 533},\n",
       "    'right_eye_left_corner': {'y': 316, 'x': 584},\n",
       "    'mouth_lower_lip_bottom': {'y': 482, 'x': 521},\n",
       "    'left_eyebrow_upper_left_quarter': {'y': 234, 'x': 459},\n",
       "    'left_eye_pupil': {'y': 283, 'x': 481},\n",
       "    'right_eyebrow_upper_left_quarter': {'y': 274, 'x': 613},\n",
       "    'contour_right8': {'y': 518, 'x': 555},\n",
       "    'right_eyebrow_right_corner': {'y': 291, 'x': 660},\n",
       "    'right_eye_upper_left_quarter': {'y': 308, 'x': 598},\n",
       "    'left_eyebrow_upper_middle': {'y': 236, 'x': 488},\n",
       "    'right_eyebrow_upper_right_quarter': {'y': 277, 'x': 650},\n",
       "    'nose_contour_left1': {'y': 304, 'x': 533},\n",
       "    'nose_contour_left2': {'y': 361, 'x': 511},\n",
       "    'mouth_upper_lip_right_contour1': {'y': 443, 'x': 545},\n",
       "    'nose_contour_right1': {'y': 312, 'x': 576},\n",
       "    'nose_contour_right2': {'y': 374, 'x': 576},\n",
       "    'mouth_lower_lip_left_contour2': {'y': 461, 'x': 478},\n",
       "    'contour_right6': {'y': 471, 'x': 596},\n",
       "    'nose_contour_right3': {'y': 409, 'x': 563},\n",
       "    'nose_contour_left3': {'y': 401, 'x': 514},\n",
       "    'left_eye_right_corner': {'y': 299, 'x': 508},\n",
       "    'left_eyebrow_upper_right_quarter': {'y': 247, 'x': 515},\n",
       "    'right_eye_upper_right_quarter': {'y': 311, 'x': 627},\n",
       "    'mouth_upper_lip_bottom': {'y': 457, 'x': 527}},\n",
       "   'attributes': {'emotion': {'sadness': 0.0,\n",
       "     'neutral': 99.951,\n",
       "     'disgust': 0.0,\n",
       "     'anger': 0.0,\n",
       "     'surprise': 0.0,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 0.048},\n",
       "    'beauty': {'female_score': 80.28, 'male_score': 81.593},\n",
       "    'gender': {'value': 'Male'},\n",
       "    'age': {'value': 25},\n",
       "    'mouthstatus': {'close': 100.0,\n",
       "     'surgical_mask_or_respirator': 0.0,\n",
       "     'open': 0.0,\n",
       "     'other_occlusion': 0.0},\n",
       "    'glass': {'value': 'None'},\n",
       "    'skinstatus': {'dark_circle': 11.623,\n",
       "     'stain': 0.724,\n",
       "     'acne': 8.775,\n",
       "     'health': 5.287},\n",
       "    'blur': {'blurness': {'threshold': 50.0, 'value': 0.848},\n",
       "     'motionblur': {'threshold': 50.0, 'value': 0.848},\n",
       "     'gaussianblur': {'threshold': 50.0, 'value': 0.848}},\n",
       "    'smile': {'threshold': 50.0, 'value': 0.58},\n",
       "    'eyestatus': {'left_eye_status': {'normal_glass_eye_open': 0.028,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.001,\n",
       "      'no_glass_eye_open': 99.97,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.002},\n",
       "     'right_eye_status': {'normal_glass_eye_open': 0.001,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 99.999,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0}},\n",
       "    'facequality': {'threshold': 70.1, 'value': 17.524},\n",
       "    'eyegaze': {'right_eye_gaze': {'position_x_coordinate': 0.521,\n",
       "      'vector_z_component': 0.998,\n",
       "      'vector_x_component': 0.007,\n",
       "      'vector_y_component': -0.06,\n",
       "      'position_y_coordinate': 0.391},\n",
       "     'left_eye_gaze': {'position_x_coordinate': 0.522,\n",
       "      'vector_z_component': 0.988,\n",
       "      'vector_x_component': 0.114,\n",
       "      'vector_y_component': 0.103,\n",
       "      'position_y_coordinate': 0.412}}},\n",
       "   'face_rectangle': {'width': 313, 'top': 231, 'left': 323, 'height': 313},\n",
       "   'face_token': 'd488b20287a4a2d952e0731ff68fbb4e'}]}"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_analyze(API_key,API_secret,face_tokens,return_landmark,return_attributes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae2c7aba",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "id": "b246be54",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3. 人脸对比 \n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "5122f242",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "liu_face01 = 'e82c22cbff0594466e10fce666499aa6'\n",
    "liu_face02 = '3c4e5f167a4ff02f33a057fbbb052cd8'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "bb54a9da",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_compare(API_key,API_secret,face_tokens01,face_tokens02):\n",
    "    url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "    payload = {\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'face_token1':liu_face01,\n",
    "        'face_token2':liu_face02\n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "id": "53f07ca8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "id": "3e293791",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647412336,7068579e-f9cc-4314-aa21-29c2b8524543',\n",
       " 'time_used': 275,\n",
       " 'confidence': 85.879,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}}"
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_compare(API_key,API_secret,liu_face01,liu_face02)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ccc5538",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "613c0d1a",
   "metadata": {},
   "source": [
    "作业2："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "844acdce",
   "metadata": {},
   "outputs": [],
   "source": [
    "#创建人脸库\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "9462dc39",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "face_tokens = 'd488b20287a4a2d952e0731ff68fbb4e'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "c7d62325",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_create(API_key,API_secret,face_tokens):\n",
    "    url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "    payload ={\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'face_tokens':face_tokens\n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "5ca9fc67",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '4d75cbab7f70455249985acb149f0bec',\n",
       " 'time_used': 563,\n",
       " 'face_count': 1,\n",
       " 'face_added': 1,\n",
       " 'request_id': '1647681315,308f84b6-1033-4bc1-a71b-a3e51ee70a04',\n",
       " 'outer_id': '',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_create(API_key,API_secret,face_tokens)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "5fdea070",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查看人脸库\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "332deacb",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "74677b6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_getfacesets(API_key,API_secret):\n",
    "    url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets\"\n",
    "    payload ={\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "4768ed3c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 73,\n",
       " 'facesets': [{'faceset_token': '4d75cbab7f70455249985acb149f0bec',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''}],\n",
       " 'request_id': '1647681333,0a288b44-7282-4c19-a906-94f84fe7ba86'}"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_getfacesets(API_key,API_secret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "d76d49e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "#删除人脸库\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "1813bfd4",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "faceset_token = '57898c7737188190f875d284af48364b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "1c6b3869",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_delete(API_key,API_secret,faceset_token):\n",
    "    url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/delete\"\n",
    "    payload ={\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'faceset_token':faceset_token\n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "1f8526a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '57898c7737188190f875d284af48364b',\n",
       " 'request_id': '1647681124,13245b50-d4a0-4800-8631-49ddccbd5362',\n",
       " 'time_used': 159,\n",
       " 'outer_id': ''}"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_delete(API_key,API_secret,faceset_token)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "1903dc89",
   "metadata": {},
   "outputs": [],
   "source": [
    "#添加人脸\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "f7b5cc0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "face_tokens = 'd488b20287a4a2d952e0731ff68fbb4e'\n",
    "faceset_token =  '57898c7737188190f875d284af48364b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "03a1cebd",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_addface(API_key,API_secret,face_tokens,faceset_token):\n",
    "    url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "    payload ={\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'face_tokens':face_tokens,\n",
    "        'faceset_token':faceset_token,\n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "6502a13a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 63,\n",
       " 'error_message': 'INVALID_FACESET_TOKEN',\n",
       " 'request_id': '1647680559,84f8f1d1-93f0-4a87-9aaf-1df149a9f747'}"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_addface(API_key,API_secret,faceset_token,face_tokens)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "3bfdedb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "#人脸搜索\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "31b9e9db",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_key = 'SMVJThrY1hoB4CDuwbI9kF1aBaZE7TNa'\n",
    "API_secret = 'Rbd67H3brlaPlhwaTgx8vwqkAop0ljBm'\n",
    "face_token = 'b4af9445c9e3b18e7417561ce889f3d3'\n",
    "faceset_token = '4d75cbab7f70455249985acb149f0bec'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "df5ae048",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_search(API_key,API_secret,face_token,facest_token,return_result_count=1):\n",
    "    url = \"https://api-cn.faceplusplus.com/facepp/v3/search\"\n",
    "    payload ={\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'face_token':face_token,\n",
    "        'faceset_token':faceset_token,\n",
    "        'return_result_count':return_result_count\n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "id": "cf99bb43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "3dd50c79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647681587,79310a4b-94dd-4060-98d5-b48db29fc8f0',\n",
       " 'time_used': 445,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'results': [{'confidence': 80.142,\n",
       "   'user_id': '',\n",
       "   'face_token': 'd488b20287a4a2d952e0731ff68fbb4e'}]}"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_search(API_key,API_secret,face_token,face_tokens)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
